<?
include "include/init.php";

$action = strtolower($_GET["action"]);

MainMenu($smarty);

if($action=="show")
{

	$tempDal = new dal_acl_permission();
	$smarty->assign("acl_permission_list",$tempDal->get_all());
	$smarty->assign("template",SelectTemplate($smarty,"acl_permission_list.tpl"));
	$smarty->display("index.tpl");	
}
elseif($action=="add")
{
	$tempDal = new dal_acl_permission();
	
	/* Assign an user object to the template */
	$smarty->assign("acl_permission",$tempDal);
	$smarty->assign("template",SelectTemplate($smarty,"acl_permission_add.tpl"));
	$smarty->display("index.tpl");	
}
elseif($action=="edit")
{
	try {
			$tempDal = new dal_acl_permission();
			$smarty->assign("acl_permission",$tempDal->get($_GET["i"]));
			$smarty->assign("template",SelectTemplate($smarty,"acl_permission_edit.tpl"));
			$smarty->display("index.tpl");
	
	}
	catch (exception $e){ 
			
		echo $e->GetMessage();
		print_r($e->gettrace());
	} 

}
elseif($action=="save")
{
	$tempObj = new obj_acl_permission();
	$tempDal = new dal_acl_permission();
	
	
	#$tempObj->set_permission_id($_POST["COLUMN.NAME"]);
	
	
	$tempObj->set_permission_id($_POST["permission_id"]);
	
	$tempObj->set_group($_POST["group"]);
	
	$tempObj->set_member($_POST["member"]);
	
	$tempObj->set_action($_POST["action"]);
	
	$tempObj->set_access($_POST["access"]);
	
	
	try {
	
		if($tempObj->get_permission_id()!="")
		{
			$tempDal->save($tempObj);
		}
		else
		{
			$tempDal->insert($tempObj);
		}
	
	}
	catch (exception $e){ 
		echo $e->GetMessage();
	} 
	
	$smarty->assign("acl_permission_list",$tempDal->get_all());
	$smarty->assign("template",SelectTemplate($smarty,"acl_permission_list.tpl"));
	$smarty->display("index.tpl");
}
elseif($action=="delete")
{
	$tempDal = new dal_acl_permission();
	
	try {
		$tempDal->delete($_GET["i"]);
	
	}
	catch (exception $e){ 	
		echo $e->GetMessage();
	} 
	
	$smarty->assign("acl_permission_list",$tempDal->get_all());
	$smarty->assign("template",SelectTemplate($smarty,"acl_permission_list.tpl"));
	$smarty->display("index.tpl");
}
?>